package com.alibaba.yinan.domain.task.service.validator;

import com.alibaba.cola.exception.BizException;
import com.alibaba.yinan.domain.task.Task;
import com.alibaba.yinan.domain.task.enums.TaskStatus;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * @ClassName DependencyCompleteValidator
 * @Author mengke
 * @create 2025/8/3 21:55
 * @Description
 */
@Slf4j
@Component
public class DependencyCompleteValidator implements DispatchValidator {
    @Override
    public void validate(Task task) {

        log.info("开始校验任务依赖是否完成，任务ID：{}", task.getId());

        if (!task.getDependencies().isEmpty()) {
            for (String dependency : task.getDependencies()) {
                if (!task.getStatus().equals(TaskStatus.COMPLETED)) {
                    log.error("任务依赖未完成，任务ID：{}", task.getId());
                    throw new BizException("任务依赖未完成");
                }
            }
        }
    }
}
